<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <a-form :form="form">
            <a-form-item style="display:none">
                <a-input v-decorator="['id']"/>
            </a-form-item>
            <a-row>
                <a-col :span="12">
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.timeType','时间类型')">
                        <a-radio-group v-model="timeType">
                            <a-radio value="longTime">{{i18n('long','长期')}}</a-radio>
                            <a-radio value="shortTime">{{i18n('short','短期')}}</a-radio>
                        </a-radio-group>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.validTime','有效期')">
                        <a-date-picker :allowClear="false" v-model="activeTime" :disabled="timeType!='shortTime'" />
                    </a-form-item>
                </a-col>
            </a-row>
        </a-form>
    </rx-dialog>
</template>
<script>
    import BpmAuthApi from '@/api/bpm/core/bpmAuth'
    import {BaseForm,RxDialog} from '@lowcode/jpaas-common-lib';
    export default {
        name: 'BpmAuthSetActiveTime',
        mixins:[BaseForm],
        components: {
            RxDialog,
        },
        data() {
            return {
                timeType: '',
                activeTime:null
            }
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "bpmUserAccess", key);
            },
            onload_(values){
                if(values){
                    if(values.activeTime=='longTime'){
                        this.timeType='longTime';
                        this.activeTime=new moment();
                    }else{
                        this.timeType='shortTime';
                        this.activeTime=new moment(values.activeTime);
                    }
                }
            },
            get(id){
                return BpmAuthApi.get(id);
            },
            save(values){
                if(this.timeType=='longTime'){
                    values.activeTime='longTime';
                }else{
                    values.activeTime=this.activeTime.format('YYYY-MM-DD');
                }
                return BpmAuthApi.save(values);
            }

        }
    }
</script>
